package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysDictTree;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ISysDictTreeService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 树形字典管理Controller
 *
 * @author ruoyi
 * @date 2025-06-06
 */
@RestController
@RequestMapping("/system/dict/tree")
public class SysDictTreeController extends BaseController {
    @Autowired
    private ISysDictTreeService sysDictTreeService;

    /**
     * 查询树形字典管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:dictTree:list')")
    @GetMapping("/list")
    public AjaxResult list(SysDictTree sysDictTree) {
        List<SysDictTree> list = sysDictTreeService.selectSysDictTreeList(sysDictTree);
        return AjaxResult.success(list);
    }

    /**
     * 导出树形字典管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:dictTree:export')")
    @Log(title = "树形字典管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysDictTree sysDictTree) {
        List<SysDictTree> list = sysDictTreeService.selectSysDictTreeList(sysDictTree);
        ExcelUtil<SysDictTree> util = new ExcelUtil<SysDictTree>(SysDictTree.class);
        return util.exportExcel(list, "树形字典管理数据");
    }

    /**
     * 获取树形字典树信息
     */
    @GetMapping(value = "/getTree/{dictType}")
    public AjaxResult getTree(@PathVariable("dictType") String dictType) {
        return AjaxResult.success(sysDictTreeService.selectSysDictTreeByDictType(dictType));
    }

    /**
     * 获取树形字典管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dictTree:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysDictTreeService.selectSysDictTreeById(id));
    }

    /**
     * 新增树形字典管理
     */
    @PreAuthorize("@ss.hasPermi('system:dictTree:add')")
    @Log(title = "树形字典管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDictTree sysDictTree) {
        return toAjax(sysDictTreeService.insertSysDictTree(sysDictTree));
    }

    /**
     * 修改树形字典管理
     */
    @PreAuthorize("@ss.hasPermi('system:dictTree:edit')")
    @Log(title = "树形字典管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDictTree sysDictTree) {
        return toAjax(sysDictTreeService.updateSysDictTree(sysDictTree));
    }

    /**
     * 删除树形字典管理
     */
    @PreAuthorize("@ss.hasPermi('system:dictTree:remove')")
    @Log(title = "树形字典管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysDictTreeService.deleteSysDictTreeByIds(ids));
    }
}
